#include <iostream>
#include "spot.h"
using namespace std;

Distance spots[]={//总数绝对不是total个
    云谷寺,白鹅岭,65,180,0,
    云谷寺,白鹅新站,0,0,80,
    石笋崖,白鹅新站,8,18,0,
    白鹅新站,白鹅岭,6,15,0,
    始信峰,石笋崖,8,30,0,
    始信峰,北海宾馆狮林大酒店,12,30,0,
    大王松,北海宾馆狮林大酒店,2,5,0,
    北海宾馆狮林大酒店,猴子观海,15,25,0,
    猴子观海,松谷庵站,95,260,0,
    排云楼宾馆排云亭西海饭店,大王松,7,25,0,
    丹霞峰,排云楼宾馆排云亭西海饭店,10,15,0,
    白鹅岭,光明顶,12,55,0,
    白云宾馆,光明顶,5,20,0,
    白云宾馆,迎客松,35,120,0,
    天海站,白云宾馆,3,10,0,
    排云楼宾馆排云亭西海饭店,光明顶,22,80,0,
    步仙桥,吊桥庵,85,180,0,
    白云宾馆,步仙桥,28,60,0,
    排云溪站,排云楼宾馆排云亭西海饭店,28,120,0,
    迎客松,天都峰,20,90,0,
    迎客松,新道口,30,90,0,
    天都峰,新道口,25,120,0,
    新道口,慈光阁,35,90,0,
    玉屏索道上站,迎客松,5,20,0,
    排云溪站,天海站,0,0,100,
    松谷庵站,丹霞站,0,0,80,
    慈光阁,玉屏索道上站,0,0,90





};
    
int way_total=sizeof(spots)/16;
int main()
{
    extern const char *enum_spot_str[];
    //cout<<sizeof(spots)/16;

    Way ways[total+1]={};
    spot found_old[total]={};
    spot found_old_copy[total]={};
    spot found_new[total]={云谷寺};
    spot found_new_copy[total]={云谷寺};
    spot unfound[total]={};
    spot unfound_copy[total]={};
    spot all[total-1]={};
    int init=0;
    while (init<=total-1){
        unfound[init]=(spot)(init+1);
        init++;
    };
    drop(云谷寺, unfound);
    init=0;
    while (init<=total-2){
        all[init]=(spot)(init+2);
        init++;
    };
    //showSpots(all,total-1);
    //cout<<cost_simple(白鹅岭,石笋崖,spots);
    //showSpots(unfound);
    //showSpots(found_new);
    //showSpots(found_old);


    //int ans = cost_simple(云谷寺,白鹅岭,spots);
    //cout<<ans;
//}
    //cout<<(int)unfound[1]<<endl;没有声明的结构体内部都是0

    bool found=false;
    int distance_between_them;
    while (!found) {
        deep_copy(found_new,found_new_copy);
        deep_copy(unfound,unfound_copy);
        deep_copy(found_old,found_old_copy);
        cout<<"新一轮循环开始，更新使用的节点们";
        showSpots(found_new_copy,total);//并没有把新的加进来？？？
        //cout<<endl;


        for(spot found_news : found_new_copy){
            if((int)found_news){//由于变量都在动态变化这里需要深拷贝一次，淦
                for(spot alls : all){
                    distance_between_them=cost_simple(alls,found_news,spots);
                    if(distance_between_them){
                        cout<<"当起点是"<<enum_spot_str[(int)found_news]<<",";
                        cout<<"终点是"<<enum_spot_str[(int)alls]<<",";
                        cout<<"代价是"<<distance_between_them+ways[found_news].cost<<endl;
                        if(ways[alls].cost){

                            if(distance_between_them+ways[found_news].cost<ways[alls].cost){
                                ways[alls].cost=distance_between_them+ways[found_news].cost;//到这个点的距离是两个加起来～～
                                //cout<<distance_between_them<<ways[unfounds].cost;
                                insert(alls, found_new);
                                editPath(ways,(int)alls,(int)found_news,found_news);
                                ways[alls].steps=ways[found_news].steps+1;
                                //cout<<ways[alls].path<<endl;//没有改变但是指针还是被清空了！！！

                            }
                            //cout<<ways[0].steps<<endl;//不对
                        //还有一种只走这里，所以修改信息的不能统一放最后
                        }

                        else{
                            ways[alls].cost=distance_between_them+ways[found_news].cost;
                            insert(alls, found_new);
                            editPath(ways,(int)alls,(int)found_news,found_news);
                            //cout<<ways[alls].path<<endl;
                            ways[alls].steps=ways[found_news].steps+1;
                        }
                        //cout<<ways[0].steps<<endl;//不对了
                        ////cout<<ways[alls].path<<"sfd"<<endl;

                        //ways[alls].steps=ways[found_news].steps+1;//不是++我操
                        //cout<<ways[found_news].steps+1<<endl<<endl;
                        //editPath(ways,(int)alls,(int)found_news,found_news);
                        //cout<<ways[unfounds].path<<endl;//还是0
                        //insert(alls, found_new);
                        //drop(alls, unfound);
                        
                    };
                
                };
            //cout<<ways[0].steps<<endl;//no
            drop(found_news, found_new);
            insert(found_news, found_old);
            //cout<<ways[0].steps<<"??"<<endl;//no
            };
            
        };
        //cout<<ways[0].steps<<endl;//已经不对了

        cout<<"在一轮执行完后，路线状态如下"<<endl;
        //cout<<ways[1].path<<endl;//怎么是0？
        //showSpots(found_new,total);
        //showSpots(found_old,total);
        //cout<<
        showWays(ways);
        
        short flag=0;
        for(spot found_news : found_new){
            if(found_news!=0){
                flag++;
            }
        }
        cout<<"还有"<<flag<<"个景点未计算完成(新更新的，待进一步计算的节点数)"<<endl<<endl;
        if(!flag){
            found=true;
        }
        

    }//while
    return 0;
};